package com.mall.cart.vo;

import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.Data;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;

/**
 * @author: 谢君臣
 * @Date: 2022/8/8-13:40
 * @version: 1.0
 * @function:
 */
public class CartVo {
    List<CartItemVo> items;
    @ApiModelProperty(value = "商品个数")
    private Integer countNum;
    @ApiModelProperty(value = "类别个数")
    private Integer countType;
    @ApiModelProperty(value = "折扣额度")
    private BigDecimal reduce = new BigDecimal("0");
    private BigDecimal totalAmount;

    public List<CartItemVo> getItems() {
        return items;
    }

    public void setItems(List<CartItemVo> items) {
        this.items = items;
        if (items!=null)
            setCountNum(items.size());
    }

    public Integer getCountNum() {
        return countNum;
    }

    public void setCountNum(Integer countNum) {
        this.countNum = countNum;
    }

    public Integer getCountType() {
        return countType;
    }

    public void setCountType(Integer countType) {
        this.countType = countType;
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }

    public BigDecimal getTotalAmount() {
        BigDecimal decimal = new BigDecimal("0");
        for (CartItemVo item : this.items) {
            if (item.isCheck()) {
                decimal  = decimal.add(item.getTotalPrice());
            }
        }
        decimal = decimal.subtract(getReduce());
        setTotalAmount(decimal);
        return decimal;
    }

    public void setTotalAmount(BigDecimal totalAmount) {
        this.totalAmount = totalAmount;
    }
}
